package com_2;

import java.io.IOException;
import java.net.*;

public class SendUDP {///定义一个发送类
    public static void main(String[] args) throws IOException, UnknownHostException {
        //定义udp对象
        DatagramSocket dgs = new DatagramSocket();
        //创建数据并把数据打包
        byte[] bys = "大哥来了，准备挨打把".getBytes();
        //定义发送数据的长度
        int length = bys.length;//
        InetAddress adress = InetAddress.getByName("192.168.29.59");
        //获取IP地址
        int port = 10086;//获取端口
        DatagramPacket dp = new DatagramPacket(bys, length, InetAddress.getByName("192.168.29.59"), port);
        //将需要发送上午数据进行打包
        dgs.send(dp);//发送数据
        dgs.close();//关闭资源
    }
    
}
